package com.example.tms.service;

import java.util.List;

import com.example.tms.entity.EmployeeDepartment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.tms.mapper.EmployeeDepartmentMapper;

@Service
public class EmployeeDepartmentService {

    @Autowired
    private EmployeeDepartmentMapper employeeDepartmentMapper;

    public List<EmployeeDepartment> selectAll() {
        return employeeDepartmentMapper.selectList(null);
    }
    // 根据ID查询部门
    public EmployeeDepartment selectById(Integer id) {
        return employeeDepartmentMapper.selectById(id);
    }

    // 添加部门
    public int insert(EmployeeDepartment employeeDepartment) {
        return employeeDepartmentMapper.insert(employeeDepartment);
    }

    // 更新部门信息
    public int update(EmployeeDepartment employeeDepartment) {
        return employeeDepartmentMapper.updateById(employeeDepartment);
    }

    // 删除部门
    public int deleteById(Integer id) {
        EmployeeDepartment employeeDepartment = new EmployeeDepartment();
        employeeDepartment.setId(id);
        employeeDepartment.setIsDeleted(1); // 设置为逻辑删除
        return employeeDepartmentMapper.updateById(employeeDepartment);
    }

    // 根据员工ID查询部门
    public List<EmployeeDepartment> selectByEmpId(Integer empId) {
        return employeeDepartmentMapper.selectByEmpId(empId);
    }

    // 根据部门ID查询员工
    public List<EmployeeDepartment> selectByDepId(Integer depId) {
        return employeeDepartmentMapper.selectByDepId(depId);
    }

    // 获取当前部门
    public EmployeeDepartment getCurrentDepartment(Integer empId) {
        return employeeDepartmentMapper.selectCurrentByEmpId(empId);
    }

    // 获取所有待审批的人事调动
    public List<EmployeeDepartment> getPendingTransfers() {
        return employeeDepartmentMapper.selectPendingTransfers();
    }

    // 获取指定创建人的所有人事调动申请
    public List<EmployeeDepartment> getTransfersByCreator(Integer creatorId) {
        return employeeDepartmentMapper.selectTransfersByCreator(creatorId);
    }
}
